package clientCommunicationHandler;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import communication.*;

public class ReadNewMsg {
	String subject;
	String body;
	boolean needBody;
	public ReadNewMsg (){
		this.subject = null;
		this.body = null;
		needBody = true;
	}

	public String readMsgFromUser(){
		this.readSubject();
		this.readBody();
		return this.subject+(char)1+this.body;
	}

	private void readBody() {
//		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String tMsgBody = "";
		while(needBody){
			System.out.println("enter message body");
			if(subject != "")
				needBody = false;
			try {
				tMsgBody = TelnetClient.in.readLine();
				if(tMsgBody.equals("\n") && needBody){
					needBody = true;
					System.out.println("you cant have a massage without a subject and with message body.. please enter body");		
				}

			} catch (IOException e) {
				e.printStackTrace();
				tMsgBody = "";
			}
			this.body = tMsgBody;


		}
	}
	private void readSubject() {
//		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		System.out.println("enter message subject");
		try {
			subject =TelnetClient.in.readLine();
			if(subject.equals("\n")){
				subject = "";		
			}
		} catch (IOException e) {
			e.printStackTrace();
			subject = "";
		}
	}
}
